package org.fireflow2.designer.eclipse.modelwrapper.basic;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.fireflow.pdl.fpdl20.diagram.DiagramElement;
import org.fireflow.pdl.fpdl20.diagram.Fpdl20DiagramElement;
import org.fireflow.pdl.fpdl20.diagram.StartNodeShape;
import org.fireflow.pdl.fpdl20.diagram.basic.Circle;
import org.fireflow.pdl.fpdl20.process.StartNode;
import org.fireflow2.designer.eclipse.figures.StartNodeFigure;
import org.fireflow2.designer.eclipse.modelwrapper.NodeWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.SubProcessWrapper;
import org.fireflow2.designer.eclipse.util.Util4Eclipse;

public class StartNodeWrapper extends NodeWrapper {
	String attachedToWrapperId = null;

	public String getAttachedToWrapperId() {
		return attachedToWrapperId;
	}

	public void setAttachedToWrapperId(String attachedToWrapperId) {
		this.attachedToWrapperId = attachedToWrapperId;
	}

	public StartNodeWrapper(SubProcessWrapper subflowWrapper,StartNode arg0,DiagramElement arg1){
		super(subflowWrapper,arg0,arg1);
	}
	
	public  String getElementType(){
		return Fpdl20DiagramElement.START_NODE.name();
	}			
	
	public Rectangle calculateBounds(){
		String displayName = this.getDisplayName();
		StartNodeShape startShape = (StartNodeShape)this.getDiagramElement();
		Circle circle = (Circle)startShape.getShape();

		Dimension dimension = Util4Eclipse.getTextSize(circle.getLabel(),displayName);
		
		Rectangle rectangle = this.getBox();
		if (dimension.width>0){
			rectangle.height+=StartNodeFigure.IconTextGap;
			rectangle.height+=dimension.height;//字体高度
			if (dimension.width>rectangle.width){
				int oldWidth = rectangle.width;
				rectangle.width = dimension.width;
				rectangle.x -= ((dimension.width-oldWidth)/2);
			}
		}
		return rectangle;
	}
}
